package com.viu.technology.dto;

import com.viu.technology.util.JsonUtil;
import org.msgpack.annotation.Message;

//Netty中使用MessagePack传输对象需要在对象的类加此注解

/**
 * type--0：token认证，data为String类型的token
 *       1：聊天消息，data为ChatMessage实体类
 *       2：聊天消息ack，data为String类型的ChatMessage.messageId
 *       3：聊天消息nack，data为String类型的ChatMessage.messageId
 *       4：异常
 */
@Message
public class IMMessage {

    private String msg;

    private Object data;

    private Integer type;

    private Long date;

    public IMMessage() {
    }

    public IMMessage(String msg, Object data, Integer type) {
        this.msg = msg;
        this.data = data;
        this.type = type;
        this.date = System.currentTimeMillis();
    }


    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Long getDate() {
        return date;
    }

    public void setDate(Long date) {
        this.date = date;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    @Override
    public String toString() {
        JsonUtil jsonUtil = new JsonUtil();
        return jsonUtil.objectToJsonObject(this).toString();
    }

    public static void main(String args[]){
        String data = "{\"senderId\":\"123\",\"sendDate\":1531297564147,\"receiptDate\":0,\"messageId\":\"12300000001\",\"recipientId\":\"124\",\"content\":\"这是一条消息\",\"status\":1}";
        IMMessage message = new IMMessage( "this is a message", data, 1);
        System.out.println(message);
    }

}
